﻿using System;
using System.Collections.Generic;
namespace xiaohongshu
{
    class Sol4
    {
        public int CalculateUgliness(int n, int[] categories, int[] movable)
        {

            int[] fixedCategories = new int[n];
            Array.Copy(categories, fixedCategories, n);
            for (int i = 0; i < n; i++)
            {
                if (movable[i] == 1)
                {
                    fixedCategories[i] = 0;
                }
            }

            int unsightliness = 0;
            int[] dp = new int[n];
            dp[0] = 0;

            for (int i = 1; i < n; i++)
            {
                if (fixedCategories[i] == 0)
                {
                    dp[i] = dp[i - 1];
                }
                else
                {
                    dp[i] = dp[i - 1] + (fixedCategories[i] != fixedCategories[i - 1] ? 1 : 0);
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (movable[i] == 1)
                {
                    int left = i > 0 ? fixedCategories[i - 1] : 0;
                    int right = i < n - 1 ? fixedCategories[i + 1] : 0;

                    if (left != 0 && right != 0 && left != right)
                    {
                        dp[i] = Math.Min(dp[i], dp[i - 1]);
                    }
                }
            }
            unsightliness = dp[n - 1];
            return unsightliness;
        }

    }

    class Program4
    {
        public static void Main4(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {

                string[] tokens = line.Split();
                int n = int.Parse(tokens[0]);
                line = Console.ReadLine();
                tokens = line.Split();
                int[] categories = new int[n];

                for (int i = 0; i < n; i++)
                {
                    categories[i] = int.Parse(tokens[i]);
                }

                line = Console.ReadLine();
                tokens = line.Split();
                int[] movable = new int[n];

                for (int i = 0; i < n; i++)
                {
                    movable[i] = int.Parse(tokens[i]);
                }

                Sol4 sol = new Sol4();
                int res = sol.CalculateUgliness(n, categories, movable);
                Console.WriteLine(res);
            }
        }
    }

}